﻿using MediatR;
using Microsoft.AspNetCore.Mvc;
using RearLivestock.Beginning.Api.Application.Command.Common;
using RearLivestock.Beginning.Api.Application.Command.PigArchives;
using RearLivestock.Common.Dtos;
using Yitter.IdGenerator;

namespace RearLivestock.Beginning.Api.Controllers
{
    /// <summary>
    /// 猪只档案基本信息控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class BasicsController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public BasicsController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 品种显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchVarieties(SearchVarietiesCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 基本信息添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> AddBasic(AddBasicCommand cmd)
        {
            cmd.Electronicearlabel = YitIdHelper.NextId().ToString();
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 获取耳号
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchBasic(SearchBasicCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 返填栋舍栏位
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchBedroomField(SearchEarBedroomFieldCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 猪只类型显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> SearchPigType(SearchPigTypeCommand cmd)
        {
            return await mediator.Send(cmd);
        }
        /// <summary>
        /// 猪只列表显示
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<BasicDto>>> SearchPigBasic(SearchPigBasicCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 猪只详情
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> DetailsPigfile(DetailsPigfileCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取父亲耳号
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> GetFatherearNumber([FromQuery]SearchFatherCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 获取母亲耳号
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result> GetMotherearNumber([FromQuery] SearchMotherCommand cmd)
        {
            return await mediator.Send(cmd);
        }
    }
}
